package cd.safe.school.activity;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.telephony.TelephonyManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import cd.safe.school.R;

public class SendMessage extends Activity implements OnClickListener {
	private EditText phones;
	private ListView msgs;
	private EditText msg_edit;
	private Button send;
	private ImageView msg_img;
	private boolean tag = false;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.sendmsg);
		phones = (EditText) findViewById(R.id.phones);
		msgs = (ListView) findViewById(R.id.msg);
		send = (Button) findViewById(R.id.send);
		msg_edit = (EditText) findViewById(R.id.msg_edit);
		msg_img = (ImageView) findViewById(R.id.msg_img);
		msg_img.setImageResource(R.drawable.ic_launcher);
		String ph = getIntent().getStringExtra("phones");
		phones.setText(ph);

		send.setOnClickListener(this);

		// String[] phone = ph.split(";");
		// for (String s : phone) {
		// // 发送短信
		// // SmsManager sms = SmsManager.getDefault();
		// // sms.sendTextMessage(s, null, "neirong", null, null);
		// }

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.send:
			String phs = phones.getText().toString();
			final String content = msg_edit.getText().toString();
			final String[] ps = phs.split(";");

			new Thread(new Runnable() {

				@Override
				public void run() {
					for (int i = 0; i < ps.length; i++) {
						SmsManager sms = SmsManager.getDefault();

						Intent sendIntent = new Intent("lab.sodino.sms.send");
						PendingIntent sendPI = PendingIntent.getBroadcast(
								SendMessage.this, 0, sendIntent, 0);
						sms.sendTextMessage(ps[i], null, content, sendPI, null);
					}
				}
			}).start();

			break;
		case R.id.msg_img:

			break;

		}

	}
}
